home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4960 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: Incrementing enumerated types
  5. Date: Thu, 01 Feb 1996 16:13:20 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4eqoq2$bi5@news.halcyon.com>
  8. References: <Andy.Law-3101961138310001@pc0734.ri.bbsrc.ac.uk>
  9. NNTP-Posting-Host: blv-pm2-ip25.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Doubtless not legal because enum values needn't be consecutive.
  13. enum bleah { error=-1, empty, argle, bargle, targle=4, zargle=8 }.
  14.  
  15. Use the enum where a programmer must read the code, like in switch
  16. statements, conditionals, intializations, but cast it to int in the
  17. for-loop (if you're positive it's values are consecutive, like indices
  18. into an array).
  19.  
  20.  
  21. Andy.Law@bbsrc.ac.uk (Andy Law) wrote:
  22.  
  23. >Is it legal to increment an enumerated type? I have an enumerated list of
  24. >possible document types that I want to step through, and my compiler is
  25. >barfing on it. It seems such a waste of an enumeration if I have to resort
  26. >to ints to get this done.
  27.  
  28. >Alternatively does anyone have a suggestion as to how to do this kind of
  29. >thing legally?
  30.  
  31. >for (EnumeratedType eIndex = enum_first; eIndex < enum_last; eIndex++) {
  32. >                                                             ^^^^^^^^
  33. >    /* do something */
  34. >}
  35.  
  36. >TIA,
  37.  
  38. >Andy Law
  39. >------------------
  40. >( Andy.Law@bbsrc.ac.uk )
  41. >( Big Nose in Edinburgh )
  42.  
  43.  
  44.